package cn.hfatec.shms.web.yk.ykDbbmx.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.yk.ykDbbmx.model.YkDbbmx;
import cn.hfatec.shms.web.yk.ykDbbmx.dao.YkDbbmxDao;
import cn.hfatec.shms.web.yk.ykDbbmx.model.YkDbbmxParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("YkDbbmxService")
public class YkDbbmxService {

    public static final String BEAN_ID = "YkDbbmxService";

    //注入Dao层
    @Resource(name = "YkDbbmxDao")
    private YkDbbmxDao ykDbbmxDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param ykDbbmxParams
     * @param page
     *
     */
    @Transactional
    public Table queryYkDbbmxTable(YkDbbmxParams ykDbbmxParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", ykDbbmxParams);
        return baseDao.queryTableByPage("queryYkDbbmx", params, page);
    }

    /**
     *
     * 插入数据
     * @param ykDbbmx
     *
     */
    @Transactional
    public void saveYkDbbmx(YkDbbmx ykDbbmx) {
        if(ykDbbmx.getId() != null) {
            YkDbbmx result = getYkDbbmx(ykDbbmx.getId());
            if(result != null) {
                ykDbbmxDao.update(ykDbbmx);
            } else {
                ykDbbmxDao.insert(ykDbbmx);
            }
        } else {
            ykDbbmxDao.insert(ykDbbmx);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteYkDbbmx(Integer id) {

        ykDbbmxDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param ykDbbmxList
     *
     */
    @Transactional
    public void deleteYkDbbmxBatch(List<String> ykDbbmxList) {
        for(String id : ykDbbmxList) {
            deleteYkDbbmx(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public YkDbbmx getYkDbbmx(Integer id) {

        return ykDbbmxDao.getYkDbbmxById(id);
    }
}